package org.jarge.fundAssistant.implies;

import java.util.Map;
import java.util.Set;

import org.jarge.fundAssistant.enties.Fund;
import org.jarge.fundAssistant.interfaces.IFundDataHandler;

public class FundDataHandlerImpl implements IFundDataHandler {

	public double getFloatingPerFund(Fund fund) {
		return getValuePerFund(fund)-fund.getTotalDevotion();
	}

	public double getValuePerFund(Fund fund) {
		return fund.getQuantity() * fund.getRealValue();
	}

	public double getTotalFloating(Map<String, Fund> funds) {
		double totalDevotion = 0d;
		double totalValue = getTotalValue(funds);
		Set<String> keyset = funds.keySet();
		for (String fundCode : keyset) {
			Fund temp = funds.get(fundCode);
			totalDevotion += temp.getTotalDevotion();
		}
		return totalValue-totalDevotion;
	}

	public double getTotalValue(Map<String, Fund> funds) {
		double totalValue = 0d;
		Set<String> keyset = funds.keySet();
		for (String fundCode : keyset) {
			Fund temp = funds.get(fundCode);
			totalValue += getValuePerFund(temp);
		}
		return totalValue;
	}

	public double getTodayFloating(Fund fund) {
		
		return (fund.getYesterdayValue()*fund.getQuantity())*fund.getRealFloating()/100;
	}

}
